<?php
/**
 * 乐刷仓储类
 * User: 13651
 * Time: 2025/9/18 11:53
 */

namespace App\Repository;

use App\Models\LeshuaUionMccModel;

class LeshuaUionMccRepo extends CommonRepo
{

    /**
     * 数据入库
     * @param array $data
     * @param int $id
     * @return bool
     */
    public function saveData(array $data,int $id=0)
    {
        if ($id) {
            $result  = LeshuaUionMccModel::query()->find($id);
        } else {
            $result = new LeshuaUionMccModel();
        }
        if (empty($result))
            return 0;
        collect($data)->map(function ($val, $field) use ($result) {
            $result->{$field} = $val;
        });
        return $result->save() ? $result->id : 0;
    }

    /**
     * 根據行業名稱獲取信息
     * @param string $name
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function getByNameinfo(string $name)
    {
        return LeshuaUionMccModel::query()->where('mcc_txt','like','%'.$name.'%')->get();
    }
}